<?php
/**
 * @package			ALM ProductControl
 * @version			$Id:$
 * @subpackage		com_almapc
 * @autor			ALM Studio
 * @copyright		Copyrights ALM Studio 2011. All rights reserved
 * @autor url		http://alm-studio.net
 * @autor email		info@almstudio.net
 */
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class ALMPCViewType extends JView
{
	protected $form;
	protected $item;
	protected $state;
	
	public function display($tpl = null) 
	{
		$this->form		= $this->get('Form');
		$this->item		= $this->get('Item');
		$this->state	= $this->get('State');

		if (count($errors = $this->get('Errors'))) 
		{
			JError::raiseError(500, implode('<br />', $errors));
			return false;
		}
		$this->addToolBar();
		
		parent::display($tpl);
		$this->setDocument();
	}

	protected function addToolBar() 
	{
		JRequest::setVar('hidemainmenu', true);
		$isNew = ($this->item->TypeId == 0);
		JToolBarHelper::title($isNew ? JText::_('COM_ALMPC_NEW_TYPE') : JText::_('COM_ALMPC_EDIT_TYPE'), 'type');
		JToolBarHelper::apply('type.apply', 'COM_ALMPC_TOOLBAR_APPLY');
		JToolBarHelper::save('type.save', 'COM_ALMPC_TOOLBAR_SAVE');
		JToolBarHelper::custom('type.save2new', 'save-new.png', 'save-new_f2.png', 'COM_ALMPC_TOOLBAR_SAVE2NEW', false);
		JToolBarHelper::cancel('type.cancel', $isNew ? 'COM_ALMPC_TOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE');
	}

	protected function setDocument() 
	{
		$isNew = ($this->item->TypeId < 1);
		$document = JFactory::getDocument();
		$document->setTitle($isNew ? JText::_('COM_ALMPC_TYPE_NEW') : JText::_('COM_ALMPC_TYPE_EDIT'));
	}
}
